﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using FluentAssertions;
using MementoClient.ViewModels;
using MementoClientConnectorInterfaces;
using MementoLibrary.DTOs;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace MementoClient.Tests.Unit
{
    [TestClass]
    public class WorkLogVMTest
    {
        [TestMethod]
        public void CategoryGroup_ShouldBeAvailable_IfNoneOfItsCategoriesHaveBeenIncluded()
        {
            CategoryDTO category = new CategoryDTO();
            CategoryGroupDTO categoryGroup = new CategoryGroupDTO();
            categoryGroup.Name = "Financial Status";
            categoryGroup.Categories = new ObservableCollection<CategoryDTO> { category };
            var workLog = new WorkLogVM() { };
            workLog.CategoryGroups = new [] {categoryGroup};

            workLog.AvailableCategoryGroups.Should().HaveCount(1);
            workLog.AvailableCategoryGroups.First().Name.Should().Be("Financial Status");    
        }

        [TestMethod]
        public void CategoryGroup_ShouldNotBeAvailable_IfOneOfItsCategoriesHaveBeenIncluded()
        {
            CategoryDTO category = new CategoryDTO();
            CategoryGroupDTO categoryGroup = new CategoryGroupDTO();
            categoryGroup.Categories = new ObservableCollection<CategoryDTO> { category };
            var categoryGroups = new[] {categoryGroup};
            var workLog = new WorkLogVM() { Categories = new ObservableCollection<CategoryDTO> { category } };
            workLog.CategoryGroups = categoryGroups;
            workLog.AvailableCategoryGroups.Should().HaveCount(0);
        }

        [TestMethod]
        public void CategoryGroup_ShouldNotBeAvailable_IfOneOfItsCategoriesHaveBeenIncluded_EvenWhenMultipleCategoriesAreInCategoryGroup()
        {
            CategoryDTO category = new CategoryDTO();
            CategoryDTO category2 = new CategoryDTO();
            CategoryGroupDTO categoryGroup = new CategoryGroupDTO();
            categoryGroup.Categories = new ObservableCollection<CategoryDTO> { category, category2 };
            var categoryGroups = new[] { categoryGroup };
            var workLog = new WorkLogVM() { Categories = new ObservableCollection<CategoryDTO> { category } };
            workLog.CategoryGroups = categoryGroups;
            workLog.AvailableCategoryGroups.Should().HaveCount(0);
        }

        [TestMethod]
        public void WhenAddThisCategoryCalled_PropertyChangeNotificationShouldBeRaisedForAvailableCategoryGroups()
        {
            var workLog = new WorkLogVM() {  };
            List<string> propertiesChanged = new List<string>();
            workLog.PropertyChanged += (sender, args) => propertiesChanged.Add(args.PropertyName);
            
            workLog.AddThisCategoryExecute(null);
            
            propertiesChanged.Should().Contain("AvailableCategoryGroups");
        }
    }
}
